<template>
	<view>
		<tabs @setSwipterData="setSwipterData" :tabList="tabItems"></tabs>
		<view>
			<!-- 列表 -->
			<view v-for="(item, index) in collects.records" :key="index" v-if="collects.records.length > 0" :hidden="item == null"
			 class="list" @tap="goDetail" :data-index="index" :data-id="item.id">
				<view class="list-title">
					{{item.title}}
					<text class="list-status">
						{{item.status==0?"审核中":item.status==1?"审核通过":item.status==2?"招工完成":""}}
					</text>
				</view>
				<view class="list-claim">详情：{{item.claim}}</view>
				<view class="list-date">发布时间：{{item.gmtModified}}</view>
			</view>
			<view v-if="!collects.records">
				<view class="list">
					<view class="list-title">暂时没有数据</view>
					<view class="list-company">详情：None</view>
					<view class="list-date">发布时间：None</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// pages/ucenter/collect/collect.js
	const app = getApp();
	import tabs from "../../../components/tabs/tabs";

	export default {
		data() {
			return {
				tabItems: [
					["招工信息", "", true],
					["招工记录", "", false]
				],
				current: 1,
				index: 0,
				collects: {},
				userInfo: {}
			};
		},

		components: {
			tabs
		},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.onGetUserInfo();
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			let current = this.current;
			let index = this.index;
			this.onGetData(current, index);
			uni.stopPullDownRefresh();
		},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			let current = this.current;

			if (current < this.collects.pages) {
				let current = this.current;
				let index = this.index;
				this.onGetData(current, index);
			}
		},
		methods: {
			setSwipterData(e) {
				const index = e.detail;
				this.setData({
					index
				});
				let current = this.current;
				if (index == 0) {
					this.onGetData(current, index);
				}

				if (index == 1) {
					this.onGetData(current, index);
				}

			},

			goDetail(e) {
				let id = e.currentTarget.dataset.id;
				uni.navigateTo({
					url: `/pages/common/detail/detail?id=${id}`
				});
			},

			onGetData(current = 1, typeOfWork = 0) {
				let _this = this;

				let userId = this.userInfo.id;
				uni.showLoading({
					title: '加载中',
					success: res => {
						uni.request({
							url: `${app.globalData.baseUrl}/collect/page/${current}/${userId}?typeOfWork=${typeOfWork}`,
							complete: res => {
								uni.hideLoading();
							},
							fail: res => {
								uni.showToast({
									title: '加载失败',
									icon: "none"
								});
							},
							success: result => {
								if (result.data.dataMap.data == null) {
									_this.setData({
										collects: {}
									});
								} else {
									_this.setData({
										collects: result.data.dataMap.data
									});
								}
							}
						});
					}
				});
			},

			onGetUserInfo() {
				let openid = uni.getStorageSync('openid');

				let _this = this;

				if (!openid) {
					uni.navigateBack({
						complete: res => {
							uni.showToast({
								title: '请登录',
								icon: "none"
							});
						}
					});
				} else {
					uni.request({
						url: `${app.globalData.baseUrl}/user/selectIsUser/${openid}`,
						complete: res => {},
						success: result => {
							_this.setData({
								userInfo: result.data.dataMap.data
							});

							_this.onGetData();
						}
					});
				}
			},

			onShareTimeline() {}

		}
	};
</script>
<style>
	/* pages/ucenter/collect/collect.wxss */
	.list {
		width: 95%;
		height: 200rpx;
		margin: 2.5%;
		border-bottom: solid 1px #e6e6ee;
		background: #fff;
		padding: 5rpx 10rpx;
	}

	.list-title {
		font-size: 40rpx;
		margin-top: 20rpx;
	}

	.list-date {
		margin-top: 10rpx;
	}

	.list-claim {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.list-status {
		float: right;
		font-size: small;
		color: red;
	}

	page {
		background: #efeff5;
	}
</style>
